#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys, os

from loguru import logger

from PyQt5.QtWidgets import QApplication, QWidget
sys.path.append(os.getcwd())

from qt_material import apply_stylesheet

from views.widgets import Ui_data_management
from models import data_record

class DataManagementForm(QWidget, Ui_data_management.Ui_DataManagementForm):
    def __init__(self, parent = None):
        super(DataManagementForm, self).__init__(parent)
        self.setupUi(self)

        # add function for buttons
        self.parentMainWindow = None
        self.NewExperimentButton.clicked.connect(self.newExperiment)
        self.ImgAnalysisButton.clicked.connect(self.imageAnalysis)
        self.PrintButton.clicked.connect(self.printSetting)

        logger.debug("create an instance of DataManagementForm successfully")

    def setMainWindow(self, MainWindow):
        self.parentMainWindow = MainWindow
            
    def setDataRecord(self, dataRecord):
        self.paiDataRecord = dataRecord
        self.DataTableView.setModel(self.paiDataRecord)

    def newExperiment(self):
        if self.parentMainWindow is not None:
            self.parentMainWindow.newExperiment()
        else:
            pass
    
    def imageAnalysis(self):
        if self.parentMainWindow is not None:
            self.parentMainWindow.imageAnalysis()
        else:
            pass

    def printSetting(self):
        if self.parentMainWindow is not None:
            self.parentMainWindow.printSetting()
        else:
            pass

if __name__ == "__main__":
    app = QApplication(sys.argv)
    PAWin = DataManagementForm()
    
    apply_stylesheet(app, theme = "dark_teal.xml")
    PAWin.show()
    sys.exit(app.exec_())